﻿using Jst.Application.Contracts.IApplication.Auth;
using Jst.Application.Contracts.IApplication.Auth.Dtos;
using Jst.Application.Contracts.IApplication.Auth.Vos;
using Jst.Domain.Shared.Models;
using Microsoft.AspNetCore.Mvc;

namespace Jst.EntityFrameworkCore.Controllers
{
    /// <summary>
    /// 鉴权
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AuthController : ControllerBase
    {
        private readonly IAuthService _authService;

        public AuthController(IAuthService authService)
        {
            _authService = authService;
        }

        /// <summary>
        /// 换取令牌
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> UserloginAuthAsync([FromBody]InputDto dto) => await _authService.UserloginAuthAsync(dto);

        /// <summary>
        /// 刷新令牌
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<OutputVo> RefreshTokenAsync([FromBody]RefreshTokenDto dto)=>await _authService.RefreshTokenAsync(dto);

        /// <summary>
        /// 注销令牌
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<bool> CancelTokenAsync([FromQuery]string accessToken)=>await _authService.CancelTokenAsync(accessToken);

    }
}
